/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.jfonia.view.elements;

import java.util.Arrays;
import java.util.List;
import org.jfonia.connect5.basics.MutableValueNode;
import org.jfonia.connect5.basics.ValueNode;
import org.jfonia.connect5.basics.Observer;
import org.jfonia.model.ISequence;
import org.jfonia.model.elements.Chord;
import org.jfonia.model.elements.MusicalElement;
import org.jfonia.view.SequenceView;
import percussiongenerator.model.Pair;

/**
 *
 * @author Rik Bauwens
 */
public class ChordField extends AbstractField
{

        public ChordField(ValueNode<Double> frameX, ValueNode<Double> staffY,
                          ValueNode<Double> frameWidth, MutableValueNode<Double> staffHeight,
                          Chord chord, SequenceView sequenceView)
        {
                super(frameX, staffY, frameWidth, staffHeight, chord, sequenceView);
                init();
        }

        private void init()
        {
                getChord().getChordNode().addObserver( new Observer() {
                        public void onNotify(Object source)
                        {
                                setText(getChord().getChord());
                        }
		});
                setText(getChord().getChord());
        }

        private Chord getChord()
        {
                return (Chord) musicalElement;
        }

        public List<Pair<ISequence, MusicalElement>> getMusicalElements()
        {
                return Arrays.asList(new Pair<ISequence, MusicalElement>(
                        sequenceView.getChordSequence(), musicalElement));
        }
}
